home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / gcc / ixemul-4.lha / ixemul-41.4 / include / rpc / svc.h < prev    next >
C/C++ Source or Header  |  1994-02-23  |  9KB  |  281 lines

  1. /* @(#)svc.h    2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
  2. /*
  3.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4.  * unrestricted use provided that this legend is included on all tape
  5.  * media and as a part of the software program in whole or part.  Users
  6.  * may copy or modify Sun RPC without charge, but are not authorized
  7.  * to license or distribute it to anyone else except as part of a product or
  8.  * program developed by the user.
  9.  * 
  10.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13.  * 
  14.  * Sun RPC is provided with no support and without any obligation on the
  15.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  16.  * modification or enhancement.
  17.  * 
  18.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20.  * OR ANY PART THEREOF.
  21.  * 
  22.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23.  * or profits or other special, indirect and consequential damages, even if
  24.  * Sun has been advised of the possibility of such damages.
  25.  * 
  26.  * Sun Microsystems, Inc.
  27.  * 2550 Garcia Avenue
  28.  * Mountain View, California  94043
  29.  */
  30.  
  31. /*
  32.  * svc.h, Server-side remote procedure call interface.
  33.  *
  34.  * Copyright (C) 1984, Sun Microsystems, Inc.
  35.  */
  36.  
  37. #ifndef __SVC_HEADER__
  38. #define __SVC_HEADER__
  39.  
  40. /*
  41.  * This interface must manage two items concerning remote procedure calling:
  42.  *
  43.  * 1) An arbitrary number of transport connections upon which rpc requests
  44.  * are received.  The two most notable transports are TCP and UDP;  they are
  45.  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  46.  * they in turn call xprt_register and xprt_unregister.
  47.  *
  48.  * 2) An arbitrary number of locally registered services.  Services are
  49.  * described by the following four data: program number, version number,
  50.  * "service dispatch" function, a transport handle, and a boolean that
  51.  * indicates whether or not the exported program should be registered with a
  52.  * local binder service;  if true the program's number and version and the
  53.  * port number from the transport handle are registered with the binder.
  54.  * These data are registered with the rpc svc system via svc_register.
  55.  *
  56.  * A service's dispatch function is called whenever an rpc request comes in
  57.  * on a transport.  The request's program and version numbers must match
  58.  * those of the registered service.  The dispatch function is passed two
  59.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  60.  */
  61.  
  62. enum xprt_stat {
  63.     XPRT_DIED,
  64.     XPRT_MOREREQS,
  65.     XPRT_IDLE
  66. };
  67.  
  68. /*
  69.  * Server side transport handle
  70.  */
  71. typedef struct {
  72.     int        xp_sock;
  73.     u_short        xp_port;     /* associated port number */
  74.     struct xp_ops {
  75.         bool_t    (*xp_recv)();     /* receive incomming requests */
  76.         enum xprt_stat (*xp_stat)(); /* get transport status */
  77.         bool_t    (*xp_getargs)(); /* get arguments */
  78.         bool_t    (*xp_reply)();     /* send reply */
  79.         bool_t    (*xp_freeargs)();/* free mem allocated for args */
  80.         void    (*xp_destroy)(); /* destroy this struct */
  81.     } *xp_ops;
  82.     int        xp_addrlen;     /* length of remote address */
  83.     struct sockaddr_in xp_raddr;     /* remote address */
  84.     struct opaque_auth xp_verf;     /* raw response verifier */
  85.     caddr_t        xp_p1;         /* private */
  86.     caddr_t        xp_p2;         /* private */
  87. } SVCXPRT;
  88.  
  89. /*
  90.  *  Approved way of getting address of caller
  91.  */
  92. #define svc_getcaller(x) (&(x)->xp_raddr)
  93.  
  94. /*
  95.  * Operations defined on an SVCXPRT handle
  96.  *
  97.  * SVCXPRT        *xprt;
  98.  * struct rpc_msg    *msg;
  99.  * xdrproc_t         xargs;
  100.  * caddr_t         argsp;
  101.  */
  102. #define SVC_RECV(xprt, msg)                \
  103.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  104. #define svc_recv(xprt, msg)                \
  105.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  106.  
  107. #define SVC_STAT(xprt)                    \
  108.     (*(xprt)->xp_ops->xp_stat)(xprt)
  109. #define svc_stat(xprt)                    \
  110.     (*(xprt)->xp_ops->xp_stat)(xprt)
  111.  
  112. #define SVC_GETARGS(xprt, xargs, argsp)            \
  113.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  114. #define svc_getargs(xprt, xargs, argsp)            \
  115.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  116.  
  117. #define SVC_REPLY(xprt, msg)                \
  118.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  119. #define svc_reply(xprt, msg)                \
  120.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  121.  
  122. #define SVC_FREEARGS(xprt, xargs, argsp)        \
  123.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  124. #define svc_freeargs(xprt, xargs, argsp)        \
  125.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  126.  
  127. #define SVC_DESTROY(xprt)                \
  128.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  129. #define svc_destroy(xprt)                \
  130.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  131.  
  132.  
  133. /*
  134.  * Service request
  135.  */
  136. struct svc_req {
  137.     u_long        rq_prog;    /* service program number */
  138.     u_long        rq_vers;    /* service protocol version */
  139.     u_long        rq_proc;    /* the desired procedure */
  140.     struct opaque_auth rq_cred;    /* raw creds from the wire */
  141.     caddr_t        rq_clntcred;    /* read only cooked cred */
  142.     SVCXPRT    *rq_xprt;        /* associated transport */
  143. };
  144.  
  145.  
  146. /*
  147.  * Service registration
  148.  *
  149.  * svc_register(xprt, prog, vers, dispatch, protocol)
  150.  *    SVCXPRT *xprt;
  151.  *    u_long prog;
  152.  *    u_long vers;
  153.  *    void (*dispatch)();
  154.  *    int protocol;  /* like TCP or UDP, zero means do not register 
  155.  */
  156. extern bool_t    svc_register();
  157.  
  158. /*
  159.  * Service un-registration
  160.  *
  161.  * svc_unregister(prog, vers)
  162.  *    u_long prog;
  163.  *    u_long vers;
  164.  */
  165. extern void    svc_unregister();
  166.  
  167. /*
  168.  * Transport registration.
  169.  *
  170.  * xprt_register(xprt)
  171.  *    SVCXPRT *xprt;
  172.  */
  173. extern void    xprt_register();
  174.  
  175. /*
  176.  * Transport un-register
  177.  *
  178.  * xprt_unregister(xprt)
  179.  *    SVCXPRT *xprt;
  180.  */
  181. extern void    xprt_unregister();
  182.  
  183.  
  184.  
  185.  
  186. /*
  187.  * When the service routine is called, it must first check to see if it
  188.  * knows about the procedure;  if not, it should call svcerr_noproc
  189.  * and return.  If so, it should deserialize its arguments via 
  190.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  191.  * svcerr_decode should be called followed by a return.  Successful
  192.  * decoding of the arguments should be followed the execution of the
  193.  * procedure's code and a call to svc_sendreply.
  194.  *
  195.  * Also, if the service refuses to execute the procedure due to too-
  196.  * weak authentication parameters, svcerr_weakauth should be called.
  197.  * Note: do not confuse access-control failure with weak authentication!
  198.  *
  199.  * NB: In pure implementations of rpc, the caller always waits for a reply
  200.  * msg.  This message is sent when svc_sendreply is called.  
  201.  * Therefore pure service implementations should always call
  202.  * svc_sendreply even if the function logically returns void;  use
  203.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  204.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  205.  * case of a batched call, svc_sendreply should NOT be called since
  206.  * this would send a return message, which is what batching tries to avoid.
  207.  * It is the service/protocol writer's responsibility to know which calls are
  208.  * batched and which are not.  Warning: responding to batch calls may
  209.  * deadlock the caller and server processes!
  210.  */
  211.  
  212. extern bool_t    svc_sendreply();
  213. extern void    svcerr_decode();
  214. extern void    svcerr_weakauth();
  215. extern void    svcerr_noproc();
  216. extern void    svcerr_progvers();
  217. extern void    svcerr_auth();
  218. extern void    svcerr_noprog();
  219. extern void    svcerr_systemerr();
  220.     
  221. /*
  222.  * Lowest level dispatching -OR- who owns this process anyway.
  223.  * Somebody has to wait for incoming requests and then call the correct
  224.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  225.  * svc_run never returns.
  226.  * Since another (co-existant) package may wish to selectively wait for
  227.  * incoming calls or other events outside of the rpc architecture, the
  228.  * routine svc_getreq is provided.  It must be passed readfds, the
  229.  * "in-place" results of a select system call (see select, section 2).
  230.  */
  231.  
  232. /*
  233.  * Global keeper of rpc service descriptors in use
  234.  * dynamic; must be inspected before each call to select 
  235.  */
  236. #ifdef FD_SETSIZE
  237. extern fd_set svc_fdset;
  238. #define svc_fds svc_fdset.fds_bits[0]    /* compatibility */
  239. #else
  240. extern int svc_fds;
  241. #endif /* def FD_SETSIZE */
  242.  
  243. /*
  244.  * a small program implemented by the svc_rpc implementation itself;
  245.  * also see clnt.h for protocol numbers.
  246.  */
  247. extern void rpctest_service();
  248.  
  249. extern void    svc_getreq();
  250. extern void    svc_getreqset();    /* takes fdset instead of int */
  251. extern void    svc_run();      /* never returns */
  252.  
  253. /*
  254.  * Socket to use on svcxxx_create call to get default socket
  255.  */
  256. #define    RPC_ANYSOCK    -1
  257.  
  258. /*
  259.  * These are the existing service side transport implementations
  260.  */
  261.  
  262. /*
  263.  * Memory based rpc for testing and timing.
  264.  */
  265. extern SVCXPRT *svcraw_create();
  266.  
  267. /*
  268.  * Udp based rpc.
  269.  */
  270. extern SVCXPRT *svcudp_create();
  271. extern SVCXPRT *svcudp_bufcreate();
  272.  
  273. /*
  274.  * Tcp based rpc.
  275.  */
  276. extern SVCXPRT *svctcp_create();
  277.  
  278.  
  279.  
  280. #endif !__SVC_HEADER__
  281.